home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Text / Duplicate_Line.bsh < prev    next >
Encoding:
Text File  |  2004-08-29  |  1.8 KB  |  71 lines

  1. /*
  2.  * Duplicate_Line.bsh - a BeanShell macro script for the
  3.  * jEdit text editor - duplicates the cursor line.
  4.  * Copyright (C) 2001 Francesc Roses
  5.  * froses@menta.net
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version 2
  10.  * of the License, or any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with the jEdit program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  *
  21.  *
  22.  * $Id: Duplicate_Line.bsh,v 1.2 2001/11/06 15:04:21 jgellene Exp $
  23.  *
  24.  * Checked for jEdit 4.0 API
  25.  *
  26.  */
  27.  
  28. void duplicateLine()
  29. {
  30.     /*
  31.      * Guard for readonly files becuase Buffer.insert()
  32.      * ignores the flag
  33.      *
  34.      */
  35.     if(buffer.isReadOnly())
  36.     {
  37.         Macros.error(view, "This file is read only.");
  38.         return;
  39.     }
  40.     line = textArea.getCaretLine();
  41.     offset = textArea.getLineEndOffset(line);
  42.     // handle last line differently
  43.     if(line == textArea.getLineCount() - 1)
  44.     {
  45.         text = "\n" + textArea.getLineText(line);
  46.         --offset;
  47.     }
  48.     else
  49.         text = textArea.getLineText(line) + "\n";
  50.     buffer.insert(offset, text);
  51.     textArea.goToNextLine(false);
  52. }
  53.  
  54. duplicateLine();
  55.  
  56. /*
  57.  
  58. Macro index data (in DocBook format)
  59.  
  60.   <listitem>
  61.     <para><filename>Duplicate_Line.bsh</filename></para>
  62.     <abstract><para>
  63.       Duplicates the line on which the caret lies immediately
  64.       beneath it and moves the caret to the new line.
  65.     </para></abstract>
  66.   </listitem>
  67.  
  68. */
  69.  
  70. // end Duplicate_Line.bsh
  71.